﻿namespace RPCenter.WindowsAPI
{
    using System;
    using System.Runtime.CompilerServices;
    using System.Runtime.ConstrainedExecution;
    using System.Runtime.InteropServices;
    using System.Text;

    public class ApiDefinitions
    {
        public const ulong CM_LOCATE_DEVNODE_NORMAL = 0L;
        public const ulong CM_REENUMERATE_NORMAL = 0L;
        public const uint CONNECT_UPDATE_PROFILE = 1;
        public const int CR_SUCCESS = 0;
        public const int CREATE_NEW_CONSOLE = 0x10;
        public const int CREATE_UNICODE_ENVIRONMENT = 0x400;
        public const uint DDD_EXACT_MATCH_ON_REMOVE = 4;
        public const uint DDD_REMOVE_DEFINITION = 2;
        public const int ERROR_INSUFFICIENT_BUFFER = 0x7a;
        public const uint ERROR_NO_DATA = 0xe8;
        public const uint ERROR_NONE_MAPPED = 0x534;
        public const uint EWX_FORCEIFHUNG = 0x10;
        public const int GCL_HICON = -14;
        public const int GCL_HICONSM = -34;
        public const int HCF_HIGHCONTRASTON = 1;
        public static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff);
        public const int HWND_NOTOPMOST = -2;
        public const int HWND_TOPMOST = -1;
        public const int MOD_ALT = 1;
        public const int MOD_CONTROL = 2;
        public const uint NETSETUP_ACCT_CREATE = 2;
        public const uint NETSETUP_ACCT_DELETE = 2;
        public const uint NETSETUP_DOMAIN_JOIN_IF_JOINED = 0x20;
        public const uint NETSETUP_JOIN_DOMAIN = 1;
        public const uint NO_ERROR = 0;
        public const uint NO_INHERITANCE = 0;
        public const uint PROCESS_QUERY_INFORMATION = 0x400;
        public const uint PROCESS_VM_READ = 0x10;
        public const uint PROCESSBASICINFORMATION = 0;
        public const uint PT_LOCAL = 0;
        public const uint PT_MANDATORY = 4;
        public const uint PT_ROAMING = 2;
        public const uint PT_TEMPORARY = 1;
        public const uint RESOURCETYPE_DISK = 1;
        public const uint SC_ENUM_PROCESS_INFO = 0;
        public const uint SC_MANAGER_ALL_ACCESS = 0xf003f;
        public const uint SC_MANAGER_CREATE_SERVICE = 2;
        public const uint SC_MANAGER_ENUMERATE_SERVICE = 4;
        public const uint SECURITY_DESCRIPTOR_REVISION = 1;
        public const uint SERVICE_ACTIVE = 1;
        public const uint SERVICE_ALL_ACCESS = 0xf01ff;
        public const uint SERVICE_CHANGE_CONFIG = 2;
        public const uint SERVICE_DELETE = 0x10000;
        public const uint SERVICE_DRIVER = 11;
        public const uint SERVICE_ERROR_NORMAL = 1;
        public const uint SERVICE_NO_CHANGE = uint.MaxValue;
        public const uint SERVICE_QUERY_CONFIG = 1;
        public const uint SERVICE_WIN32 = 0x30;
        public const uint SERVICE_WIN32_OWN_PROCESS = 0x10;
        public const uint SHTDN_REASON_FLAG_PLANNED = 0x80000000;
        public const int SPI_SETHIGHCONTRAST = 0x43;
        public const int SPIF_SENDWININICHANGE = 2;
        public const uint STYPE_DISKTREE = 0;
        public const int SWP_NOMOVE = 2;
        public const int SWP_NOSIZE = 1;
        public const int VK_CONTROL = 0x11;
        public const uint WM_CLOSE = 0x10;
        public const int WM_FONTCHANGE = 0x1d;
        public const uint WM_GETICON = 0x7f;
        public const int WM_HOTKEY = 0x312;

        [DllImport("gdi32.dll", EntryPoint="AddFontResourceW", SetLastError=true)]
        public static extern int AddFontResource([In, MarshalAs(UnmanagedType.LPTStr)] string lpszFilename);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll")]
        public static extern bool AllocConsole();
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll", EntryPoint="ChangeServiceConfigW", SetLastError=true)]
        public static extern bool ChangeServiceConfig([In] IntPtr hService, uint dwServiceType, uint dwStartType, uint dwErrorControl, [In, MarshalAs(UnmanagedType.LPWStr)] string lpBinaryPathName, [In, MarshalAs(UnmanagedType.LPWStr)] string lpLoadOrderGroup, IntPtr lpdwTagId, [In, MarshalAs(UnmanagedType.LPWStr)] string lpDependencies, [In, MarshalAs(UnmanagedType.LPWStr)] string lpServiceStartName, [In, MarshalAs(UnmanagedType.LPWStr)] string lpPassword, [In, MarshalAs(UnmanagedType.LPWStr)] string lpDisplayName);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll", SetLastError=true)]
        public static extern bool CloseHandle(IntPtr hObject);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll", SetLastError=true)]
        public static extern bool CloseServiceHandle([In] IntPtr hSCObject);
        [DllImport("Cfgmgr32.dll", SetLastError=true)]
        public static extern uint CM_Locate_DevNode(ref uint PdnDevInst, int pDeviceID, ulong ulFlags);
        [DllImport("Cfgmgr32.dll", SetLastError=true)]
        public static extern uint CM_Reenumerate_DevNode(uint dnDevInst, ulong ulFlags);
        [DllImport("advapi32.dll", SetLastError=true)]
        public static extern bool ControlService(IntPtr hService, SERVICE_CONTROL_CODES dwControl, ref SERVICE_STATUS_PROCESS lpServiceStatus);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("Userenv.dll", SetLastError=true)]
        public static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, [In] IntPtr hToken, [MarshalAs(UnmanagedType.Bool)] bool bInherit);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll", EntryPoint="CreateProcessAsUserW", SetLastError=true)]
        public static extern bool CreateProcessAsUser([In] IntPtr hToken, [In, MarshalAs(UnmanagedType.LPWStr)] string lpApplicationName, [In, Out, MarshalAs(UnmanagedType.LPWStr)] string lpCommandLine, [In] IntPtr lpProcessAttributes, [In] IntPtr lpThreadAttributes, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandles, uint dwCreationFlags, [In] IntPtr lpEnvironment, [In, MarshalAs(UnmanagedType.LPWStr)] string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
        [DllImport("advapi32.dll", EntryPoint="CreateServiceW", SetLastError=true)]
        public static extern IntPtr CreateService([In] IntPtr hSCManager, [In, MarshalAs(UnmanagedType.LPWStr)] string lpServiceName, [In, MarshalAs(UnmanagedType.LPWStr)] string lpDisplayName, uint dwDesiredAccess, uint dwServiceType, uint dwStartType, uint dwErrorControl, [In, MarshalAs(UnmanagedType.LPWStr)] string lpBinaryPathName, [In, MarshalAs(UnmanagedType.LPWStr)] string lpLoadOrderGroup, IntPtr lpdwTagId, [In, MarshalAs(UnmanagedType.LPWStr)] string lpDependencies, [In, MarshalAs(UnmanagedType.LPWStr)] string lpServiceStartName, [In, MarshalAs(UnmanagedType.LPWStr)] string lpPassword);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll", EntryPoint="DefineDosDeviceW", SetLastError=true)]
        public static extern bool DefineDosDevice(uint dwFlags, [In, MarshalAs(UnmanagedType.LPWStr)] string lpDeviceName, [In, MarshalAs(UnmanagedType.LPWStr)] string lpTargetPath);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("Userenv.dll", EntryPoint="DeleteProfileW", SetLastError=true)]
        public static extern bool DeleteProfile([In, MarshalAs(UnmanagedType.LPTStr)] string lpSidString, [In, MarshalAs(UnmanagedType.LPTStr)] string lpProfilePath, [In, MarshalAs(UnmanagedType.LPTStr)] string lpComputerName);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll", SetLastError=true)]
        public static extern bool DeleteService(IntPtr hService);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("Userenv.dll", SetLastError=true)]
        public static extern bool DestroyEnvironmentBlock([In] IntPtr lpEnvironment);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool DestroyIcon([In] IntPtr hIcon);
        [DllImport("Netapi32.dll", EntryPoint="DsGetDcNameW", SetLastError=true)]
        internal static extern uint DsGetDcName([In, MarshalAs(UnmanagedType.LPTStr)] string computerName, [In, MarshalAs(UnmanagedType.LPTStr)] string domainName, [In] IntPtr domainGuid, [In, MarshalAs(UnmanagedType.LPTStr)] string siteName, [In] int flags, out IntPtr domainControllerInfo);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool EnumChildWindows([In] IntPtr hWndParent, EnumWindowsProc lpEnumFunc, [MarshalAs(UnmanagedType.SysInt)] IntPtr lParam);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("PowrProf.dll", SetLastError=true)]
        public static extern bool EnumPwrSchemes(EnumPowerSchemesProc lpfnPwrSchemesEnumProc, IntPtr lParam);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll", EntryPoint="EnumServicesStatusExW", SetLastError=true)]
        public static extern bool EnumServicesStatusEx([In] IntPtr hSCManager, uint InfoLevel, uint dwServiceType, uint dwServiceState, IntPtr lpServices, uint cbBufSize, out uint pcbBytesNeeded, out uint lpServicesReturned, IntPtr lpResumeHandle, [In, MarshalAs(UnmanagedType.LPWStr)] string pszGroupName);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, [MarshalAs(UnmanagedType.SysInt)] IntPtr lParam);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
        [DllImport("shell32.dll", EntryPoint="ExtractIconExW", CallingConvention=CallingConvention.StdCall, SetLastError=true)]
        public static extern uint ExtractIconEx([In, MarshalAs(UnmanagedType.LPWStr)] string lpszFile, int nIconIndex, ref IntPtr phiconLarge, ref IntPtr phiconSmall, uint nIcons);
        [DllImport("user32.dll", SetLastError=true)]
        public static extern IntPtr FindWindowExW([In] IntPtr hWndParent, [In] IntPtr hWndChildAfter, [In, MarshalAs(UnmanagedType.LPWStr)] string lpszClass, [In, MarshalAs(UnmanagedType.LPWStr)] string lpszWindow);
        [DllImport("user32.dll", SetLastError=true)]
        public static extern IntPtr FindWindowW([In, MarshalAs(UnmanagedType.LPWStr)] string lpClassName, [In, MarshalAs(UnmanagedType.LPWStr)] string lpWindowName);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool FlashWindowEx([In] ref FLASHWINFO pfwi);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll")]
        public static extern bool FreeConsole();
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll", SetLastError=true)]
        public static extern bool FreeLibrary([In] IntPtr hLibModule);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("PowrProf.dll", SetLastError=true)]
        public static extern bool GetActivePwrScheme(out uint uiID);
        [DllImport("user32.dll", EntryPoint="GetClassLongW", SetLastError=true)]
        public static extern IntPtr GetClassLong([In] IntPtr hWnd, int nIndex);
        [DllImport("user32.dll", EntryPoint="GetClassLongPtrW", SetLastError=true)]
        public static extern IntPtr GetClassLongPtr([In] IntPtr hWnd, int nIndex);
        [DllImport("user32.dll", EntryPoint="GetClassNameW", SetLastError=true)]
        public static extern int GetClassName([In] IntPtr hWnd, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpClassName, int nMaxCount);
        [DllImport("user32.dll", SetLastError=true)]
        public static extern IntPtr GetDC([In] IntPtr hWnd);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("Kernel32.dll", EntryPoint="GetDiskFreeSpaceExW", SetLastError=true)]
        public static extern bool GetDiskFreeSpaceEx([In, MarshalAs(UnmanagedType.LPWStr)] string lpDirectoryName, ref ulong lpFreeBytesAvailable, ref ulong lpTotalNumberOfBytes, ref ulong lpTotalNumberOfFreeBytes);
        [DllImport("user32.dll", SetLastError=true)]
        public static extern IntPtr GetForegroundWindow();
        [DllImport("Iphlpapi.dll", SetLastError=true)]
        public static extern uint GetInterfaceInfo([Out] IntPtr pIfTable, ref uint dwOutBufLen);
        [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail), DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
        public static extern IntPtr GetModuleHandle(string moduleName);
        [DllImport("kernel32.dll", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
        public static extern IntPtr GetProcAddress(IntPtr hModule, string methodName);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("Userenv.dll", EntryPoint="GetProfilesDirectoryW", SetLastError=true)]
        public static extern bool GetProfilesDirectory([Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpProfilesDir, ref uint lpcchSize);
        [DllImport("Userenv.dll", SetLastError=true)]
        public static extern bool GetProfileType(ref uint pdwflags);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool GetWindowRect([In] IntPtr hWnd, out RECT lpRect);
        [DllImport("user32.dll", EntryPoint="GetWindowTextW", SetLastError=true)]
        public static extern int GetWindowText([In] IntPtr hWnd, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpString, int nMaxCount);
        [DllImport("user32.dll", EntryPoint="GetWindowTextLengthW", SetLastError=true)]
        public static extern int GetWindowTextLength([In] IntPtr hWnd);
        [DllImport("user32.dll", SetLastError=true)]
        public static extern uint GetWindowThreadProcessId([In] IntPtr hWnd, out int lpdwProcessId);
        [DllImport("advapi32.dll", SetLastError=true)]
        public static extern uint InitializeSecurityDescriptor(ref SECURITY_DESCRIPTOR pSecurityDescriptor, uint dwRevision);
        [DllImport("Iphlpapi.dll", SetLastError=true)]
        public static extern uint IpReleaseAddress(ref IP_ADAPTER_INDEX_MAP AdapterInfo);
        [DllImport("Iphlpapi.dll", SetLastError=true)]
        public static extern uint IpRenewAddress(ref IP_ADAPTER_INDEX_MAP AdapterInfo);
        [DllImport("advapi32.dll", SetLastError=true)]
        public static extern uint IsValidSecurityDescriptor(ref SECURITY_DESCRIPTOR pSecurityDescriptor);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool IsWindowVisible([In] IntPtr hWnd);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll", SetLastError=true)]
        public static extern bool IsWow64Process([In] IntPtr hProcess, out bool Wow64Process);
        [DllImport("kernel32.dll", EntryPoint="LoadLibraryW", SetLastError=true)]
        public static extern IntPtr LoadLibrary([In, MarshalAs(UnmanagedType.LPWStr)] string lpLibFileName);
        [DllImport("user32.dll", EntryPoint="LoadStringW", SetLastError=true)]
        public static extern int LoadString([In] IntPtr hInstance, uint uID, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpBuffer, int cchBufferMax);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll", EntryPoint="LookupAccountSidW", SetLastError=true)]
        public static extern bool LookupAccountSid([In, MarshalAs(UnmanagedType.LPWStr)] string lpSystemName, [In] byte[] lpSid, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpName, ref uint cchName, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpReferencedDomainName, ref uint cchReferencedDomainName, out SID_NAME_USE peUse);
        [DllImport("advapi32.dll", SetLastError=true)]
        public static extern uint LsaAddAccountRights(IntPtr PolicyHandle, [In] byte[] AccountSid, [In] ref LSA_UNICODE_STRING UserRights, uint CountOfRights);
        [DllImport("advapi32.dll", SetLastError=true)]
        public static extern uint LsaClose(IntPtr ObjectHandle);
        [DllImport("advapi32.dll", SetLastError=true)]
        public static extern uint LsaNtStatusToWinError(uint Status);
        [DllImport("advapi32.dll", SetLastError=true)]
        public static extern uint LsaOpenPolicy(ref LSA_UNICODE_STRING SystemName, ref LSA_OBJECT_ATTRIBUTES ObjectAttributes, LSA_POLICY_ACCESS_MASK DesiredAccess, ref IntPtr PolicyHandle);
        [DllImport("logoncli.dll", SetLastError=true)]
        public static extern int NetAddServiceAccount([In, MarshalAs(UnmanagedType.LPWStr)] string ServerName, [In, MarshalAs(UnmanagedType.LPWStr)] string AccountName, [In, MarshalAs(UnmanagedType.LPWStr)] string Reserved, uint Flags);
        [DllImport("Netapi32.dll", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode, SetLastError=true)]
        public static extern NET_API_STATUS NetApiBufferFree([In] IntPtr Buffer);
        [DllImport("logoncli.dll", SetLastError=true)]
        public static extern int NetIsServiceAccount([In, MarshalAs(UnmanagedType.LPWStr)] string ServerName, [In, MarshalAs(UnmanagedType.LPWStr)] string AccountName, out int IsService);
        [DllImport("Netapi32.dll", SetLastError=true)]
        public static extern NET_API_STATUS NetJoinDomain([In, MarshalAs(UnmanagedType.LPWStr)] string lpServer, [In, MarshalAs(UnmanagedType.LPWStr)] string lpDomain, [In, MarshalAs(UnmanagedType.LPWStr)] string lpAccountOU, [In, MarshalAs(UnmanagedType.LPWStr)] string lpAccount, [In, MarshalAs(UnmanagedType.LPWStr)] string lpPassword, uint fJoinOptions);
        [DllImport("logoncli.dll", SetLastError=true)]
        public static extern int NetRemoveServiceAccount([In, MarshalAs(UnmanagedType.LPWStr)] string ServerName, [In, MarshalAs(UnmanagedType.LPWStr)] string AccountName, uint Flags);
        [DllImport("Netapi32.dll", SetLastError=true)]
        public static extern NET_API_STATUS NetRenameMachineInDomain([In, MarshalAs(UnmanagedType.LPWStr)] string lpServer, [In, MarshalAs(UnmanagedType.LPWStr)] string lpNewMachineName, [In, MarshalAs(UnmanagedType.LPWStr)] string lpAccount, [In, MarshalAs(UnmanagedType.LPWStr)] string lpPassword, uint fRenameOptions);
        [DllImport("netapi32.dll", SetLastError=true)]
        public static extern NET_API_STATUS NetShareAdd([In, MarshalAs(UnmanagedType.LPWStr)] string servername, uint level, [In] ref SHARE_INFO_2 buf, out uint parm_err);
        [DllImport("netapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
        public static extern NET_API_STATUS NetShareAdd([In, MarshalAs(UnmanagedType.LPWStr)] string servername, uint level, [In] ref SHARE_INFO_502 buf, out int parm_err);
        [DllImport("Netapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
        public static extern int NetShareEnum([MarshalAs(UnmanagedType.LPWStr)] string ServerName, int level, ref IntPtr BufPtr, int prefmaxbufferlen, ref int entriesread, ref int totalentries, ref IntPtr resume_handle);
        [DllImport("Netapi32.dll", SetLastError=true)]
        public static extern NET_API_STATUS NetUnjoinDomain([In, MarshalAs(UnmanagedType.LPWStr)] string lpServer, [In, MarshalAs(UnmanagedType.LPWStr)] string lpAccount, [In, MarshalAs(UnmanagedType.LPWStr)] string lpPassword, uint fUnjoinOptions);
        [DllImport("ntdll.dll", SetLastError=true)]
        public static extern int NtQueryInformationProcess(IntPtr handle, uint processinformationclass, ref Process_Basic_Information ProcessInformation, int ProcessInformationLength, ref uint ReturnLength);
        [DllImport("kernel32.dll", SetLastError=true)]
        public static extern IntPtr OpenProcess(uint dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, uint dwProcessId);
        [DllImport("advapi32.dll", EntryPoint="OpenSCManagerW", SetLastError=true)]
        public static extern IntPtr OpenSCManager([In, MarshalAs(UnmanagedType.LPWStr)] string lpMachineName, [In, MarshalAs(UnmanagedType.LPWStr)] string lpDatabaseName, uint dwDesiredAccess);
        [DllImport("advapi32.dll", EntryPoint="OpenServiceW", SetLastError=true)]
        public static extern IntPtr OpenService([In] IntPtr hSCManager, [In, MarshalAs(UnmanagedType.LPWStr)] string lpServiceName, uint dwDesiredAccess);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll", EntryPoint="QueryServiceConfigW", SetLastError=true)]
        public static extern bool QueryServiceConfig([In] IntPtr hService, [Out] IntPtr lpServiceConfig, uint cbBufSize, out uint pcbBytesNeeded);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll", SetLastError=true)]
        public static extern bool QueryServiceStatusEx([In] IntPtr hService, uint InfoLevel, IntPtr lpBuffer, uint cbBufSize, out uint pcbBytesNeeded);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll", SetLastError=true)]
        public static extern bool ReadProcessMemory([In] IntPtr hProcess, [In] IntPtr lpBaseAddress, [Out] byte[] lpBuffer, uint nSize, out uint lpNumberOfBytesRead);
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
        [DllImport("user32.dll", SetLastError=true)]
        public static extern int ReleaseDC([In] IntPtr hWnd, [In] IntPtr hDC);
        [DllImport("gdi32.dll", EntryPoint="RemoveFontResourceW", SetLastError=true)]
        public static extern int RemoveFontResource([In, MarshalAs(UnmanagedType.LPTStr)] string lpszFilename);
        [DllImport("user32.dll", EntryPoint="SendMessageW", SetLastError=true)]
        public static extern IntPtr SendMessage([In] IntPtr hWnd, uint Msg, uint wParam, int lParam);
        [DllImport("PowrProf.dll", SetLastError=true)]
        public static extern bool SetActivePwrScheme(uint uiID, [In] IntPtr lpGlobalPowerPolicy, [In] IntPtr lpPowerPolicy);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll", EntryPoint="SetComputerNameExW", SetLastError=true)]
        public static extern bool SetComputerNameEx(COMPUTER_NAME_FORMAT NameType, [In, MarshalAs(UnmanagedType.LPWStr)] string lpBuffer);
        [DllImport("advapi32.dll", EntryPoint="SetEntriesInAclW", SetLastError=true)]
        public static extern uint SetEntriesInAcl(int cCountOfExplicitEntries, [In] ref EXPLICIT_ACCESS pListOfExplicitEntries, [In] IntPtr OldAcl, ref IntPtr NewAcl);
        [DllImport("user32.dll", SetLastError=true)]
        public static extern IntPtr SetParent([In] IntPtr hWndChild, [In] IntPtr hWndNewParent);
        [DllImport("advapi32.dll", SetLastError=true)]
        public static extern uint SetSecurityDescriptorDacl(ref SECURITY_DESCRIPTOR pSecurityDescriptor, [MarshalAs(UnmanagedType.Bool)] bool bDaclPresent, [In] IntPtr pDacl, [MarshalAs(UnmanagedType.Bool)] bool bDaclDefaulted);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool SetWindowPos([In] IntPtr hWnd, [In] IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
        [DllImport("shell32.dll", EntryPoint="SHEmptyRecycleBinW", CallingConvention=CallingConvention.StdCall, SetLastError=true)]
        public static extern int SHEmptyRecycleBin(IntPtr hwnd, [In, MarshalAs(UnmanagedType.LPWStr)] string pszRootPath, uint dwFlags);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
        [DllImport("shell32.dll", EntryPoint="SHQueryRecycleBinW")]
        public static extern int SHQueryRecycleBin([In, MarshalAs(UnmanagedType.LPTStr)] string pszRootPath, ref SHQUERYRBINFO pSHQueryRBInfo);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll", EntryPoint="StartServiceW", SetLastError=true)]
        public static extern bool StartService([In] IntPtr hService, uint dwNumServiceArgs, IntPtr lpServiceArgVectors);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool SystemParametersInfoW(uint uiAction, uint uiParam, IntPtr pvParam, uint fWinIni);
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
        [DllImport("mpr.dll", EntryPoint="WNetAddConnection2W", SetLastError=true)]
        public static extern uint WNetAddConnection2(ref NETRESOURCE lpNetResource, [In, MarshalAs(UnmanagedType.LPWStr)] string lpPassword, [In, MarshalAs(UnmanagedType.LPWStr)] string lpUserName, uint dwFlags);
        [DllImport("mpr.dll", EntryPoint="WNetCancelConnection2W", SetLastError=true)]
        public static extern uint WNetCancelConnection([In, MarshalAs(UnmanagedType.LPWStr)] string lpName, uint dwFlags, [MarshalAs(UnmanagedType.Bool)] bool fForce);
        [DllImport("mpr.dll", SetLastError=true)]
        public static extern int WNetGetConnection(string lpLocalName, StringBuilder lpRemoteName, ref int lpnLength);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("Wtsapi32.dll", EntryPoint="WTSEnumerateSessionsW", SetLastError=true)]
        public static extern bool WTSEnumerateSessions(IntPtr hServer, uint Reserved, uint Version, ref IntPtr ppSessionInfo, ref uint pCount);
        [DllImport("Wtsapi32.dll")]
        public static extern void WTSFreeMemory(IntPtr pMemory);
        [DllImport("kernel32.dll", SetLastError=true)]
        public static extern uint WTSGetActiveConsoleSessionId();
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("Wtsapi32.dll", EntryPoint="WTSQuerySessionInformationW", SetLastError=true)]
        public static extern bool WTSQuerySessionInformation(IntPtr hServer, uint SessionId, WTS_INFO_CLASS WTSInfoClass, ref IntPtr ppBuffer, ref uint pBytesReturned);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("Wtsapi32.dll", SetLastError=true)]
        public static extern bool WTSQueryUserToken(uint SessionId, ref IntPtr phToken);

        public enum ACCESS_MASK : uint
        {
            CHANGE = 0x1301bf,
            DELETE = 0x10000,
            GENERIC_ALL = 0x10000000,
            GENERIC_EXECUTE = 0x20000000,
            GENERIC_READ = 0x80000000,
            GENERIC_WRITE = 0x40000000,
            READ_CONTROL = 0x20000,
            STANDARD_RIGHTS_READ = 0x20000,
            STANDARD_RIGHTS_REQUIRED = 0xf0000,
            SYNCHRONIZE = 0x100000,
            WRITE_DAC = 0x40000,
            WRITE_OWNER = 0x80000
        }

        public enum ACCESS_MODE : uint
        {
            DENY_ACCESS = 3,
            GRANT_ACCESS = 1,
            NOT_USED_ACCESS = 0,
            REVOKE_ACCESS = 4,
            SET_ACCESS = 2,
            SET_AUDIT_FAILURE = 6,
            SET_AUDIT_SUCCESS = 5
        }

        public enum COMPUTER_NAME_FORMAT
        {
            ComputerNameNetBIOS,
            ComputerNameDnsHostname,
            ComputerNameDnsDomain,
            ComputerNameDnsFullyQualified,
            ComputerNamePhysicalNetBIOS,
            ComputerNamePhysicalDnsHostname,
            ComputerNamePhysicalDnsDomain,
            ComputerNamePhysicalDnsFullyQualified,
            ComputerNameMax
        }

        [Flags]
        public enum DsGetDcNameFlags
        {
            DS_AVOID_SELF = 0x4000,
            DS_BACKGROUND_ONLY = 0x100,
            DS_DIRECTORY_SERVICE_6_REQUIRED = 0x80000,
            DS_DIRECTORY_SERVICE_PREFERRED = 0x20,
            DS_DIRECTORY_SERVICE_REQUIRED = 0x10,
            DS_FORCE_REDISCOVERY = 1,
            DS_GC_SERVER_REQUIRED = 0x40,
            DS_GOOD_TIMESERV_PREFERRED = 0x2000,
            DS_IP_REQUIRED = 0x200,
            DS_IS_DNS_NAME = 0x20000,
            DS_IS_FLAT_NAME = 0x10000,
            DS_KDC_REQUIRED = 0x400,
            DS_ONLY_LDAP_NEEDED = 0x8000,
            DS_PDC_REQUIRED = 0x80,
            DS_RETURN_DNS_NAME = 0x40000000,
            DS_RETURN_FLAT_NAME = -2147483648,
            DS_TIMESERV_REQUIRED = 0x800,
            DS_TRY_NEXTCLOSEST_SITE = 0x40000,
            DS_WEB_SERVICE_REQUIRED = 0x100000,
            DS_WRITABLE_REQUIRED = 0x1000
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct ENUM_SERVICE_STATUS_PROCESS
        {
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpServiceName;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpDisplayName;
            public ApiDefinitions.SERVICE_STATUS_PROCESS ServiceStatusProcess;
        }

        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
        public delegate bool EnumPowerSchemesProc(uint uiIndex, uint dwName, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder sName, uint dwDesc, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder sDesc, ref ApiDefinitions.POWER_POLICY pp, IntPtr lParam);

        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
        public delegate bool EnumWindowsProc(IntPtr hwnd, IntPtr lparam);

        [StructLayout(LayoutKind.Sequential)]
        public struct EXPLICIT_ACCESS
        {
            public uint grfAccessPermissions;
            public ApiDefinitions.ACCESS_MODE grfAccessMode;
            public uint grfInheritance;
            public ApiDefinitions.TRUSTEE Trustee;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct FLASHWINFO
        {
            public uint cbSize;
            public IntPtr hwnd;
            public uint dwFlags;
            public uint uCount;
            public uint dwTimeout;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct GLOBAL_MACHINE_POWER_POLICY
        {
            public uint Revision;
            public ApiDefinitions.SYSTEM_POWER_STATE LidOpenWakeAc;
            public ApiDefinitions.SYSTEM_POWER_STATE LidOpenWakeDc;
            public uint BroadcastCapacityResolution;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct GLOBAL_POWER_POLICY
        {
            public ApiDefinitions.GLOBAL_USER_POWER_POLICY user;
            public ApiDefinitions.GLOBAL_MACHINE_POWER_POLICY mach;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct GLOBAL_USER_POWER_POLICY
        {
            public uint Revision;
            public ApiDefinitions.POWER_ACTION_POLICY PowerButtonAc;
            public ApiDefinitions.POWER_ACTION_POLICY PowerButtonDc;
            public ApiDefinitions.POWER_ACTION_POLICY SleepButtonAc;
            public ApiDefinitions.POWER_ACTION_POLICY SleepButtonDc;
            public ApiDefinitions.POWER_ACTION_POLICY LidCloseAc;
            public ApiDefinitions.POWER_ACTION_POLICY LidCloseDc;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=4, ArraySubType=UnmanagedType.Struct)]
            public ApiDefinitions.SYSTEM_POWER_LEVEL[] DischargePolicy;
            public uint GlobalFlags;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct HIGHCONTRAST
        {
            public uint cbSize;
            public uint dwFlags;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string lpszDefaultScheme;
        }

        [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
        public struct IP_ADAPTER_INDEX_MAP
        {
            public int Index;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=0x80)]
            public string Name;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct IP_INTERFACE_INFO
        {
            public int NumAdapters;
            public ApiDefinitions.IP_ADAPTER_INDEX_MAP[] Adapter;
        }

        public class LOGON_RIGHT
        {
            public const string SE_BATCH_LOGON_NAME = "SeBatchLogonRight";
            public const string SE_DENY_BATCH_LOGON_NAME = "SeDenyBatchLogonRight";
            public const string SE_DENY_INTERACTIVE_LOGON_NAME = "SeDenyInteractiveLogonRight";
            public const string SE_DENY_NETWORK_LOGON_NAME = "SeDenyNetworkLogonRight";
            public const string SE_DENY_REMOTE_INTERACTIVE_LOGON_NAME = "SeDenyRemoteInteractiveLogonRight";
            public const string SE_DENY_SERVICE_LOGON_NAME = "SeDenyServiceLogonRight";
            public const string SE_INTERACTIVE_LOGON_NAME = "SeInteractiveLogonRight";
            public const string SE_NETWORK_LOGON_NAME = "SeNetworkLogonRight";
            public const string SE_REMOTE_INTERACTIVE_LOGON_NAME = "SeRemoteInteractiveLogonRight";
            public const string SE_SERVICE_LOGON_NAME = "SeServiceLogonRight";
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct LSA_OBJECT_ATTRIBUTES
        {
            public uint Length;
            public IntPtr RootDirectory;
            public IntPtr ObjectName;
            public uint Attributes;
            public IntPtr SecurityDescriptor;
            public IntPtr SecurityQualityOfService;
        }

        public enum LSA_POLICY_ACCESS_MASK : uint
        {
            POLICY_AUDIT_LOG_ADMIN = 0x200,
            POLICY_CREATE_ACCOUNT = 0x10,
            POLICY_CREATE_PRIVILEGE = 0x40,
            POLICY_CREATE_SECRET = 0x20,
            POLICY_GET_PRIVATE_INFORMATION = 4,
            POLICY_LOOKUP_NAMES = 0x800,
            POLICY_NOTIFICATION = 0x1000,
            POLICY_SERVER_ADMIN = 0x400,
            POLICY_SET_AUDIT_REQUIREMENTS = 0x100,
            POLICY_SET_DEFAULT_QUOTA_LIMITS = 0x80,
            POLICY_TRUST_ADMIN = 8,
            POLICY_VIEW_AUDIT_INFORMATION = 2,
            POLICY_VIEW_LOCAL_INFORMATION = 1
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct LSA_UNICODE_STRING
        {
            public ushort Length;
            public ushort MaximumLength;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string Buffer;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct MACHINE_POWER_POLICY
        {
            public uint Revision;
            public ApiDefinitions.SYSTEM_POWER_STATE MinSleepAc;
            public ApiDefinitions.SYSTEM_POWER_STATE MinSleepDc;
            public ApiDefinitions.SYSTEM_POWER_STATE ReducedLatencySleepAc;
            public ApiDefinitions.SYSTEM_POWER_STATE ReducedLatencySleepDc;
            public uint DozeTimeoutAc;
            public uint DozeTimeoutDc;
            public uint DozeS4TimeoutAc;
            public uint DozeS4TimeoutDc;
            public byte MinThrottleAc;
            public byte MinThrottleDc;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst=2)]
            public string pad1;
            public ApiDefinitions.POWER_ACTION_POLICY OverThrottledAc;
            public ApiDefinitions.POWER_ACTION_POLICY OverThrottledDc;
        }

        public enum MULTIPLE_TRUSTEE_OPERATION : uint
        {
            NO_MULTIPLE_TRUSTEE = 0,
            TRUSTEE_IS_IMPERSONATE = 1
        }

        public enum NET_API_STATUS
        {
            ERROR_ACCESS_DENIED = 5,
            ERROR_INVALID_LEVEL = 0x7c,
            ERROR_INVALID_NAME = 0x7b,
            ERROR_INVALID_PARAMETER = 0x57,
            ERROR_MORE_DATA = 0xea,
            ERROR_NO_SUCH_DOMAIN = 0x54b,
            NERR_ACCT_EXISTS = 0x8b0,
            NERR_BUFTOOSMALL = 0x84b,
            NERR_DUPLICATESHARE = 0x846,
            NERR_REDIRECTEDPATH = 0x845,
            NERR_SETUPNOTJOINED = 0xa84,
            NERR_SUCCESS = 0,
            NERR_UNKNOWNDEVDIR = 0x844,
            PATH_NOT_FOUND = 0x35
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct NETRESOURCE
        {
            public uint dwScope;
            public uint dwType;
            public uint dwDisplayType;
            public uint dwUsage;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string lpLocalName;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string lpRemoteName;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string lpComment;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string lpProvider;
        }

        public enum POWER_ACTION
        {
            PowerActionNone,
            PowerActionReserved,
            PowerActionSleep,
            PowerActionHibernate,
            PowerActionShutdown,
            PowerActionShutdownReset,
            PowerActionShutdownOff,
            PowerActionWarmEject
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct POWER_ACTION_POLICY
        {
            public ApiDefinitions.POWER_ACTION Action;
            public uint Flags;
            public uint EventCode;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct POWER_POLICY
        {
            public ApiDefinitions.USER_POWER_POLICY user;
            public ApiDefinitions.MACHINE_POWER_POLICY mach;
        }

        [StructLayout(LayoutKind.Sequential, Pack=1)]
        public struct Process_Basic_Information
        {
            public IntPtr ExitStatus;
            public IntPtr PebBaseAddress;
            public IntPtr AffinityMask;
            public IntPtr BasePriority;
            public IntPtr UniqueProcessID;
            public IntPtr InheritedFromUniqueProcessId;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct PROCESS_INFORMATION
        {
            public IntPtr hProcess;
            public IntPtr hThread;
            public uint dwProcessId;
            public uint dwThreadId;
        }

        [StructLayout(LayoutKind.Sequential)]
        public class QUERY_SERVICE_CONFIG
        {
            public uint dwServiceType;
            public uint dwStartType;
            public uint dwErrorControl;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string lpBinaryPathName;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string lpLoadOrderGroup;
            public uint dwTagId;
            public IntPtr lpDependencies;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string lpServiceStartName;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string lpDisplayName;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct RECT
        {
            public int left;
            public int top;
            public int right;
            public int bottom;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct SECURITY_DESCRIPTOR
        {
            public byte Revision;
            public byte Sbz1;
            public ushort Control;
            public IntPtr Owner;
            public IntPtr Group;
            public IntPtr Sacl;
            public IntPtr Dacl;
        }

        public enum SERVICE_CONTROL_CODES : uint
        {
            SERVICE_CONTROL_CONTINUE = 3,
            SERVICE_CONTROL_INTERROGATE = 4,
            SERVICE_CONTROL_NETBINDADD = 7,
            SERVICE_CONTROL_NETBINDDISABLE = 10,
            SERVICE_CONTROL_NETBINDENABLE = 9,
            SERVICE_CONTROL_NETBINDREMOVE = 8,
            SERVICE_CONTROL_PARAMCHANGE = 6,
            SERVICE_CONTROL_PAUSE = 2,
            SERVICE_CONTROL_STOP = 1
        }

        public enum SERVICE_STATES : uint
        {
            SERVICE_CONTINUE_PENDING = 5,
            SERVICE_PAUSE_PENDING = 6,
            SERVICE_PAUSED = 7,
            SERVICE_RUNNING = 4,
            SERVICE_START_PENDING = 2,
            SERVICE_STOP_PENDING = 3,
            SERVICE_STOPPED = 1
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct SERVICE_STATUS_PROCESS
        {
            public uint dwServiceType;
            public ApiDefinitions.SERVICE_STATES dwCurrentState;
            public uint dwControlsAccepted;
            public uint dwWin32ExitCode;
            public uint dwServiceSpecificExitCode;
            public uint dwCheckPoint;
            public uint dwWaitHint;
            public uint dwProcessId;
            public uint dwServiceFlags;
        }

        [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
        public struct SHARE_INFO_1
        {
            [MarshalAs(UnmanagedType.LPWStr)]
            public string shi1_netname;
            public ApiDefinitions.ShareType shi1_type;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string shi1_remark;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct SHARE_INFO_2
        {
            [MarshalAs(UnmanagedType.LPWStr)]
            public string shi2_netname;
            public uint shi2_type;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string shi2_remark;
            public uint shi2_permissions;
            public int shi2_max_uses;
            public uint shi2_current_uses;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string shi2_path;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string shi2_passwd;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct SHARE_INFO_502
        {
            [MarshalAs(UnmanagedType.LPWStr)]
            public string shi502_netname;
            public uint shi502_type;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string shi502_remark;
            public int shi502_permissions;
            public int shi502_max_uses;
            public int shi502_current_uses;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string shi502_path;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string shi502_passwd;
            public int shi502_reserved;
            public IntPtr shi502_security_descriptor;
        }

        public enum ShareType
        {
            STYPE_DEVICE = 2,
            STYPE_DISKTREE = 0,
            STYPE_IPC = 3,
            STYPE_PRINTQ = 1,
            STYPE_SPECIAL = -2147483648,
            STYPE_TEMPORARY = 0x40000000
        }

        [StructLayout(LayoutKind.Sequential, Pack=4)]
        public struct SHQUERYRBINFO
        {
            public uint cbSize;
            public ulong i64Size;
            public ulong i64NumItems;
        }

        public enum SID_NAME_USE
        {
            SidTypeAlias = 4,
            SidTypeComputer = 9,
            SidTypeDeletedAccount = 6,
            SidTypeDomain = 3,
            SidTypeGroup = 2,
            SidTypeInvalid = 7,
            SidTypeLabel = 10,
            SidTypeUnknown = 8,
            SidTypeUser = 1,
            SidTypeWellKnownGroup = 5
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct SP_DEVINFO_DATA
        {
            public uint cbSize;
            public Guid ClassGuid;
            public uint DevInst;
            public IntPtr Reserved;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct STARTUPINFO
        {
            public uint cb;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string lpReserved;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string lpDesktop;
            [MarshalAs(UnmanagedType.LPWStr)]
            public string lpTitle;
            public uint dwX;
            public uint dwY;
            public uint dwXSize;
            public uint dwYSize;
            public uint dwXCountChars;
            public uint dwYCountChars;
            public uint dwFillAttribute;
            public uint dwFlags;
            public ushort wShowWindow;
            public ushort cbReserved2;
            public IntPtr lpReserved2;
            public IntPtr hStdInput;
            public IntPtr hStdOutput;
            public IntPtr hStdError;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct SYSTEM_POWER_LEVEL
        {
            public byte Enable;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=3, ArraySubType=UnmanagedType.I1)]
            public byte[] Spare;
            public uint BatteryLevel;
            public ApiDefinitions.POWER_ACTION_POLICY PowerPolicy;
            public ApiDefinitions.SYSTEM_POWER_STATE MinSystemState;
        }

        public enum SYSTEM_POWER_STATE
        {
            PowerSystemUnspecified,
            PowerSystemWorking,
            PowerSystemSleeping1,
            PowerSystemSleeping2,
            PowerSystemSleeping3,
            PowerSystemHibernate,
            PowerSystemShutdown,
            PowerSystemMaximum
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct TRUSTEE
        {
            public uint pMultipleTrustee;
            public ApiDefinitions.MULTIPLE_TRUSTEE_OPERATION MultipleTrusteeOperation;
            public ApiDefinitions.TRUSTEE_FORM TrusteeForm;
            public ApiDefinitions.TRUSTEE_TYPE TrusteeType;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string ptstrName;
        }

        public enum TRUSTEE_FORM : uint
        {
            TRUSTEE_BAD_FORM = 2,
            TRUSTEE_IS_NAME = 1,
            TRUSTEE_IS_OBJECTS_AND_NAME = 4,
            TRUSTEE_IS_OBJECTS_AND_SID = 3,
            TRUSTEE_IS_SID = 0
        }

        public enum TRUSTEE_TYPE : uint
        {
            TRUSTEE_IS_ALIAS = 4,
            TRUSTEE_IS_COMPUTER = 8,
            TRUSTEE_IS_DELETED = 6,
            TRUSTEE_IS_DOMAIN = 3,
            TRUSTEE_IS_GROUP = 2,
            TRUSTEE_IS_INVALID = 7,
            TRUSTEE_IS_UNKNOWN = 0,
            TRUSTEE_IS_USER = 1,
            TRUSTEE_IS_WELL_KNOWN_GROUP = 5
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct USER_POWER_POLICY
        {
            public uint Revision;
            public ApiDefinitions.POWER_ACTION_POLICY IdleAc;
            public ApiDefinitions.POWER_ACTION_POLICY IdleDc;
            public uint IdleTimeoutAc;
            public uint IdleTimeoutDc;
            public byte IdleSensitivityAc;
            public byte IdleSensitivityDc;
            public byte ThrottlePolicyAc;
            public byte ThrottlePolicyDc;
            public ApiDefinitions.SYSTEM_POWER_STATE MaxSleepAc;
            public ApiDefinitions.SYSTEM_POWER_STATE MaxSleepDc;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=2, ArraySubType=UnmanagedType.U4)]
            public uint[] Reserved;
            public uint VideoTimeoutAc;
            public uint VideoTimeoutDc;
            public uint SpindownTimeoutAc;
            public uint SpindownTimeoutDc;
            public byte OptimizeForPowerAc;
            public byte OptimizeForPowerDc;
            public byte FanThrottleToleranceAc;
            public byte FanThrottleToleranceDc;
            public byte ForcedThrottleAc;
            public byte ForcedThrottleDc;
        }

        public enum WTS_CONNECTSTATE_CLASS
        {
            WTSActive,
            WTSConnected,
            WTSConnectQuery,
            WTSShadow,
            WTSDisconnected,
            WTSIdle,
            WTSListen,
            WTSReset,
            WTSDown,
            WTSInit
        }

        public enum WTS_INFO_CLASS
        {
            WTSInitialProgram,
            WTSApplicationName,
            WTSWorkingDirectory,
            WTSOEMId,
            WTSSessionId,
            WTSUserName,
            WTSWinStationName,
            WTSDomainName,
            WTSConnectState,
            WTSClientBuildNumber,
            WTSClientName,
            WTSClientDirectory,
            WTSClientProductId,
            WTSClientHardwareId,
            WTSClientAddress,
            WTSClientDisplay,
            WTSClientProtocolType,
            WTSIdleTime,
            WTSLogonTime,
            WTSIncomingBytes,
            WTSOutgoingBytes,
            WTSIncomingFrames,
            WTSOutgoingFrames,
            WTSClientInfo,
            WTSSessionInfo,
            WTSSessionInfoEx,
            WTSConfigInfo,
            WTSValidationInfo,
            WTSSessionAddressV4,
            WTSIsRemoteSession
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct WTS_SESSION_INFO
        {
            public uint SessionId;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string pWinStationName;
            public ApiDefinitions.WTS_CONNECTSTATE_CLASS State;
        }
    }
}

